https://leetcode.cn/problems/maximum-length-substring-with-two-occurrences/submissions/515846945/


class Solution {
public:
    int maximumLengthSubstring(string s) {

        unordered_map<char, int> mymap;

        int ans = 1;
        for (int i = 0; i < s.size() - 1; i++)
        {
            mymap.clear();

            mymap[s[i]]++;
            int len = 0;
            for (int j = i + 1; j < s.size(); j++)
            {
                mymap[s[j]]++;



                if (mymap[s[j]] > 2)
                    break;

                len = j - i + 1;

            }
            ans = max(ans, len);
        }
        return ans;
    }

};